package com.gec.system.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gec.model.entity.SysActivity;
import com.gec.model.vo.SysActivityQueryVo;
import com.gec.system.service.SysActivityService;
import com.gec.system.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 活动表 前端控制器
 * </p>
 *
 * @author Liangxj
 * @since 2023-12-09
 */
@Api(tags = "活动管理控制器")
@RestController
@RequestMapping("/admin/system/sysActivity")
public class SysActivityController {


    @Autowired
    private SysActivityService sysActivityService;

    @ApiOperation("分页查询活动列表")
    @GetMapping("/{page}/{limit}")
    public Result findPage(@PathVariable Long page,
                           @PathVariable Long limit,
                           SysActivityQueryVo vo){

        IPage<SysActivity> page1 = new Page<>(page,limit);
        page1 = this.sysActivityService.selectPage(page1,vo);
        return Result.ok(page1);
    }

    //查看全部
    @ApiOperation("获取全部活动信息")
    @GetMapping("/findAll")
    public Result findAll() {
        List<SysActivity> list = this.sysActivityService.findAll();
        return Result.ok(list);
    }

    //    新增
    @ApiOperation("新增活动信息")
    @PostMapping("/addActivity")
    public Result addActivity(@RequestBody SysActivity sysActivity) {
        boolean res = this.sysActivityService.save(sysActivity);
        if (res) {
            return Result.ok();
        } else {
            return Result.fail();
        }
    }

    // 修改
    //1.根据id 去得到当前分类
    @ApiOperation("根据id获取活动信息")
    @GetMapping("/findActivityById/{id}")
    public Result findActivityById(@PathVariable Long id)
    {
        SysActivity sysActivity = this.sysActivityService.getById(id);
        return Result.ok(sysActivity);
    }

    // 实现修改
    @ApiOperation("修改活动信息")
    @PostMapping("/updateActivity")
    public Result updateActivity(@RequestBody SysActivity sysActivity)
    {
        boolean b = this.sysActivityService.updateById(sysActivity);
        if (b)
        {
            return Result.ok();
        }
        else
        {
            return Result.fail();
        }
    }

    //    根据单个id 删除数据
    @ApiOperation("根据id删除活动")
    @DeleteMapping("/removeActivityById/{id}")
    public Result removeActivityById(@PathVariable Long id){

        boolean b = this.sysActivityService.removeById(id);
        if (b){
            return Result.ok();
        }
        return Result.fail();
    }

    // 批量删除
    @ApiOperation("批量删除活动信息")
    @DeleteMapping("/removeActivityByIds")
    public Result removeActivityByIds(@RequestBody List<Long> ids)
    {
        boolean b = this.sysActivityService.removeByIds(ids);

        if (b)
        {
            return Result.ok();
        }
        else
        {
            return Result.fail();
        }
    }





}

